package com.ptr.ptrsystem.ajax;

import com.ptr.controladores.conexionsqlserver;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ptr.ptrsystem.dao.Lista;

/**
 *
 * @author WALDIR
 */
@WebServlet(name = "MatrimonioAjaxservlet", urlPatterns = {"/MatrimonioAjax"})
public class MatrimonioAjaxservlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        String cod_persona = (String)request.getParameter("codpersona");
        
       
        conexionsqlserver con = new conexionsqlserver();
        Connection cn;
        Statement st;
        ResultSet rs;
        try {
            con.conectar();
            cn = con.getconection();
            st = cn.createStatement();
            String query = "select * from TB_MATRIMONIO where COD_PERSONA='" + cod_persona + "'";
            rs = st.executeQuery(query);
            if (rs.next()) {
                out.println("{nActa:'" + rs.getString("NRO_ACTA_MAT") + "',nlibro:'" + rs.getString("NRO_LIBRO") + "',nubigeo:'"+Lista.getNombreUbigeo(rs.getString("IDUBIGEO_MAT"))+"',fecha:'"+rs.getString("FECHA_REG_MAT")+"',dni1:'"+rs.getString("DNI_PERS_1")+"',ndni1:'"+Lista.getNombrePersona(rs.getString("DNI_PERS_1"))+"',dni2:'"+rs.getString("DNI_PERS_2")+"',ndni2:'"+Lista.getNombrePersona(rs.getString("DNI_PERS_2"))+"',mensage:'SI'}");
            }else
            {
                out.println("{nActa:'',nlibro:'',fecha:'',dni1:'',ndni1:'',dni2:'',ndni2:'',mensage:''}");
            }
        } catch (SQLException er) {
            er.printStackTrace();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
